<template>
  <div class="app-container">
    <ContentWrap>
      <el-tabs v-model="activeName" @tab-click="handleTabPaneClick">
        <el-tab-pane label="大表换表明细" name="first"></el-tab-pane>
        <el-tab-pane label="户表换表明细" name="second"></el-tab-pane>
      </el-tabs>
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="96px">
        <el-form-item label="用户编号" prop="TerminalID" v-if="activeName==='second'">
          <el-input
            v-model="queryParams.TerminalID"
            placeholder="请输入用户编号"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="旧表设备编号" prop="easionidOld">
          <el-input
            v-model="queryParams.easionidOld"
            placeholder="请输入原设备编号"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="新表设备编号" prop="easionidNew">
          <el-input
            v-model="queryParams.easionidNew"
            placeholder="请输入新设备编号"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="换表日期">
          <el-date-picker
            v-model="queryParams.replaceDate"
            type="date"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
            placeholder="请输入换表日期"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <el-table v-loading="loading" :data="terminalsReplaceList" border :height="getAvailableHeight">
        <!--      <el-table-column type="selection" width="55" align="center"/>-->
        <el-table-column type="index" width="40" align="center" label="#" :fixed="true"/>
        <el-table-column label="用户编号" align="center" prop="terminalID" v-if="activeName==='second'"/>
        <el-table-column label="旧表生产厂家" align="center" prop="supplieridOld">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.terminal_supplier" :value="scope.row.supplieridOld"/>
          </template>
        </el-table-column>
        <el-table-column label="旧表设备编号" align="center" prop="easionidOld"/>
        <el-table-column label="旧表读数" align="center" prop="totalflowOld"/>
        <el-table-column label="新表生产厂家" align="center" prop="supplieridNew">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.terminal_supplier" :value="scope.row.supplieridNew"/>
          </template>
        </el-table-column>
        <el-table-column label="新表设备编号" align="center" prop="easionidNew"/>
        <el-table-column label="新表读数" align="center" prop="totalflowNew"/>
        <el-table-column label="换表日期" align="center" prop="replaceDate"/>
        <el-table-column label="备注" align="center" prop="remark"/>
      </el-table>

      <pagination
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </ContentWrap>
  </div>
</template>

<script>
import {
  listTerminalsReplace,
  getTerminalsReplace,
  delTerminalsReplace,
  addTerminalsReplace,
  updateTerminalsReplace
} from "@/api/leakage/terminalsReplace";

export default {
  name: "TerminalsReplace",
  dicts: ['terminal_supplier'],
  data() {
    return {
      screenHeight: null,
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 换表明细表格数据
      terminalsReplaceList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        tenantId: null,
        supplieridOld: null,
        supplieridNew: null,
        TerminalID: null,
        easionidOld: null,
        easionidNew: null,
        totalflowOld: null,
        totalflowNew: null,
        TerminalType: null,
        replaceDate: '',
        uploadDate: null,
        Remark: null
      },
      activeName: 'first'
    };
  },
  created() {
    this.getList();
    this.screenHeight = document.body.clientHeight
  },
  computed: {
    getAvailableHeight() {
      return this.screenHeight - 254
    },
  },
  methods: {
    /** 查询换表明细列表 */
    getList() {
      this.loading = true;
      this.queryParams.terminalType = (this.activeName === 'first' ? 1 : 2)
      listTerminalsReplace(this.queryParams).then(response => {
        this.terminalsReplaceList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('device/terminalsReplace/export', {
        ...this.queryParams
      }, `terminalsReplace_${new Date().getTime()}.xlsx`)
    },
    handleTabPaneClick() {
      this.getList()
    },
  }
};
</script>
